package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.sys.SysUser;
import com.atguigu.spyx.model.dto.system.SysUserDto;
import com.atguigu.spzx.manager.service.SysUserService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author LT
 * @create 2023-11-04-13:49
 */
@RestController
@RequestMapping("/admin/system/user")
public class SysUserController {


    @Resource
    SysUserService sysUserService;

    @GetMapping("/getPage/{pageNum}/{pageSize}")
    public Result getPage(@PathVariable Integer pageNum,
                          @PathVariable Integer pageSize,
                          SysUserDto sysUserDto
    ){
        PageInfo<SysUser> pageInfo = sysUserService.getUserPage(pageNum,pageSize,sysUserDto);

        return Result.ok().data(pageInfo);

    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id")Integer id){
        sysUserService.deleteById(id);
        return Result.ok();
    }
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id")Integer id){
        SysUser sysUser = sysUserService.getById(id);
        return Result.ok().data(sysUser);
    }
    @PutMapping("/updateById")
    public Result updateById(@RequestBody SysUser sysUser){
        sysUserService.updateById(sysUser);
        return Result.ok();
    }
    @PostMapping("/save")
    public Result saveUser(@RequestBody SysUser sysUser){
        sysUserService.saveUser(sysUser);
        return Result.ok();
    }




}
